import React, { PureComponent } from 'react'
import { Button } from "antd";

export default class index extends PureComponent {
    constructor(props) {
        super();                
        this.state = {
            name:"柴正盼",
            age: 22,
            wife:{
                name:"范冰冰",
                sex:"女",
                age:21
            }
        }
    }

    changeAge = () => {
        
        // this.setState({
        //     age:this.state.age
        // });

        this.setState({
            wife:{
                ...this.state.wife,
                age:this.state.age+1
            }
        });
    }

    render() {
        console.log("render");
        return (
            <>
                <h2>性能优化(PureComponent)</h2>
                <p>年龄：{this.state.age}</p>
                <p>wife的年龄：{this.state.wife.age}</p>
                <Button type="primary" onClick={this.changeAge}>修改年龄</Button>
            </>
        )
    }
}
